{extend name="public/base" /}
{block name="body"}
<div class="layui-fluid">
  	<div class="layui-row">
    	<div class="layui-col-md12 layui-col-xs12">
			<div class="widget-head">
				<div class="widget-title">{$title}</div>
			</div>
		</div>
		<div class="layui-col-md12 layui-col-xs12 widget-body">
			<div class="layui-u-sm-3 layui-u-md-3 layui-col-lg3">
			    <!-- 工具栏 -->
				<div class="page_toolbar">
					<div class="layui-btn-group">
						<a class="layui-btn" onclick="exportData()"><i class="menu-icon fa fa-arrow-down"></i> 导出</a>
						<a href="{:url('Order/del')}" class="layui-btn ajax-batch"><i class="fa fa-trash-o"></i> 删除</a>
					</div>
				</div>		
			</div>
			<div class="layui-u-sm-9 layui-u-md-9 layui-col-lg9">
				<form class="layui-form" method="post" action="{:url('Order/index')}"> 
		    		<div class="layui-form-item">
			    		<div class="layui-input-inline">
							<input name="orderno" type="text" class="layui-input" placeholder="请输入单号" value="">	
						</div>
						<div class="layui-input-inline">
							<select name="status">
                        		<option value="">是否正常</option>
                        		<option value="1" {if condition="input('?status') and (input('status') eq 1)"} selected="selected"{/if}>是</option>
                        		<option value="0" {if condition="input('?status') and (input('status') eq 0)"} selected="selected"{/if}>否</option>
                    		</select>
						</div>
						<div class="layui-input-inline">
							<button class="layui-btn layui-btn-primary ajax-search"><i class="fa fa-search"></i></button>
						</div>
					</div>		    	
				</form>
			</div>
			<div class="layui-col-md12">
				<table class="layui-table layui-form">
					<thead>
						<tr>
							<th width="30"><input type="checkbox" lay-skin="primary" lay-filter="*"></th>
							<th>商品信息</th>
							<th>单价/数量</th>
							<th>实付</th>
							<th>买家</th>
							<th>状态</th>
							<th>操作</th>
						</tr> 
					</thead>
					<tbody>
						{empty name="list"}
						<tr>
							<td colspan="7" class="layer-text-center">暂无记录</td>
						</tr>
						{else /}
						{volist name="list" id="vo"}
							<tr>								
								<td class="layui-text-middle layui-text-left" colspan="7">
									<span class="layui-margin-right-lg">{$vo.create_time}</span>
									<span class="layui-margin-right-lg" style="margin-left: 20px">订单号：{$vo.order_no}</span>
								</td>
							</tr>
							{volist name="vo['goods']" id="item" key="k"}
							<tr>
								{eq name="k" value="1"}
								<td rowspan="{$vo.goods|count}"><input type="checkbox" name="id" value="{$vo.id}" lay-skin="primary"></td>
								{/eq}
								<td class="goods-detail layui-text-middle">
									<div class="goods-image">
										<img src="{$item.goods_image}" alt="">
									</div>
									<div class="goods-info">
										<p class="goods-title">{$item.goods_name}</p>
										<p class="goods-spec layui-link-muted">
											{$item.sku_name}
										</p>
									</div>
								</td>
								<td class="layui-text-middle">
									<p>￥{$item.goods_money}</p>
									<p>×{$item.num}</p>
								</td>
								{eq name="k" value="1"}
								<td class="layui-text-middle" rowspan="{$vo.goods|count}">
									<p>￥{$vo.pay_money}</p>
									<p class="layui-link-muted">(含运费：￥{$vo.shipping_money})</p>
								</td>
								<td class="layui-text-middle" rowspan="{$vo.goods|count}">
									<p>{$vo.member.nickname}</p>
									<p class="layui-link-muted">(会员ID：{$vo.member.id})</p>
								</td>
								<td class="layui-text-middle" rowspan="{$vo.goods|count}">
									<p>付款状态：
									{eq name="vo.pay_status" value="1"}
										<span class="layui-badge layui-bg-green">已付款</span>
									{else/}
										<span class="layui-badge layui-bg-gray">未付款</span>
									{/eq}
									</p>
									<p>发货状态：
									{eq name="vo.shipping_status" value="1"}
										<span class="layui-badge layui-bg-green">已发货</span>
									{else/}
										<span class="layui-badge layui-bg-gray">未发货</span>
									{/eq}
									</p>
									{neq name="vo.order_status" value="0"}
									<p>订单状态：
									{switch vo.order_status}
										{case -1}
    										<span class="layui-badge">已取消</span>
    									{/case}
										{case 1}
											<span class="layui-badge layui-bg-green">已完成</span>
										{/case}
    									{case 2}
    										<span class="layui-badge layui-bg-blue">已评价</span>
    									{/case}
									{/switch}
									</p>
									{/neq}									
								</td>
								<td class="layui-text-middle" rowspan="{$vo.goods|count}">
									<a href="{:url('Order/send?id='.$vo['id'])}" class="layui-btn layui-btn-xs"><i class="fa fa-paper-plane"></i> 发货</a>
									<a href="{:url('Order/info?id='.$vo['id'])}" class="layui-btn layui-btn-xs layui-btn-normal"><i class="fa fa-eye"></i> 详情</a>
									<a href="{:url('Order/del?id='.$vo['id'])}" class="layui-btn layui-btn-xs layui-btn-danger ajax-delete"><i class="fa fa-trash-o"></i> 删除</a>
								</td>
								{/eq}
							</tr>
							{/volist}
						{/volist}
						{/empty}
					</tbody>
				</table>
				<div class="layui-col-md12 layui-col-xs12">
					<div class="page">{$list->render()|raw}</div>
				</div>
			</div>
		</div>
  	</div>
</div>
{/block}
{block name="js"}
<script>
	layui.config({
		base: '/static/libs/extend/excel/'
	}).extend({
		excel: 'excel'
	});

	/**
 	 * 导出数据测试
 	 * @return {[type]}       [description]
 	 */
 	function exportData() {
  		layui.use(['jquery','excel'], function() {
			var $ = layui.jquery;
    		var excel = layui.excel;
    		// 如果数据量特别大，最好直接传入 AOA 数组，减少内存/CPU消耗
			$.get("{:url('Order/excel')}", function(result){
				var data = [
      				[ "ID", "订单号", '订单金额', '实付金额', '收货人', '时间']
    			];
				var items = JSON.parse(result);
				for(i = 0;i < items.length;i++){
					data.push([
						items[i]['id'],
						items[i]['order_no'],
						items[i]['order_money'],
						items[i]['pay_money'],
						items[i]['realname'],
						items[i]['create_time']
					]);
				}
				excel.exportExcel({
      				sheet1: data
    			}, '订单.xlsx', 'xlsx');
			})
  		});
	}
</script> 
{/block} 